package cn.silver.framework.mybatis.enums;

import cn.silver.framework.core.model.DictModel;
import cn.silver.framework.core.utils.StreamUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

/**
 * @author zhouxiaobo
 */
@Getter
@AllArgsConstructor
public enum RoleScopeEnums {
    ALL_SCOPE("00", "全部数据权限", ""),
    TENANT_SCOPE("01", "租户数据权限", ""),
    DEPT_SCOPE("02", "当前组织数据权限", ""),
    DEPT_CHI_SCOPE("03", "当前组织及下属组织数据权限", ""),
    SELF_SCOPE("90", "仅本人数据权限", ""),
    OTHER_SCOPE("99", "自定义数据权限", ""),
    ;
    private final String code;
    private final String name;
    private final String sql;
    public static RoleScopeEnums getByCode(String code) {
        return Stream.of(values()).filter(e -> e.getCode().equals(code)).findFirst().orElse(RoleScopeEnums.SELF_SCOPE);
    }
    public static List<DictModel> getModels() {
        return StreamUtils.toList(Arrays.asList(values()), item -> new DictModel(item.name, item.code));
    }
}
